package com.example.zhaohang.dagger2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.zhaohang.dagger2.dagger.DaggerMianComponent;
import com.example.zhaohang.dagger2.dagger.MainModule;
import com.example.zhaohang.mvp.presenter.MianMVPPresenter;
import com.example.zhaohang.mvp.presenter.MianMVPPresenterImpl;
import com.example.zhaohang.mvp.view.PrensentView;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity implements PrensentView {


    @Inject
    public MainPresenter mMainPresenter;
    private MianMVPPresenter mMianMVPPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //这是创建DaggerPresnter的实例引用
        DaggerMianComponent.builder().mainModule(new MainModule(MainActivity.this)).build().in(MainActivity.this);

        //声明变量采用观察者模式，面向接口的模式,多态
        mMianMVPPresenter = new MianMVPPresenterImpl(MainActivity.this);

    }
    //采用dagger2模式创建的
    public void dagger(View view) {
        String text = mMainPresenter.getText();
        Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
    }

    //采用自定义接口书写
    public void mvp(View view) {
        mMianMVPPresenter.doing();

    }


    @Override
    public void setText(String text) {
        Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
    }
}
